<?php
/*
 * Project_Name: thietkewebsangtao
 * Coder: Nguyễn Trần Minh Trung
 */

class temp_view {

    private $detail;
    public $a_temp;
    public $ran;
    public $cur_seg;
    public $cur;
    public $cat_id;
    public $lan;
    private $id;
    private $size_out;
    private $size_in = array('w' => '500', 'h' => '600');

    function __construct($lan, $cur_seg = '', $cat_id = '', $id = '', $ran = '', $size_out = array(), $detail = true) {
        $this->id = $id;
        $this->cur_seg = $cur_seg;
        $this->cat_id = $cat_id;
        $this->lan = $lan;
        $this->ran = $ran != '' ? $ran : 20;
        $this->detail = $detail;
        $this->size_out = count($size_out) > 0 ? $size_out : array('w' => '200', 'h' => '200', 'm' => '40');
        if ($id === '') {
            $this->get_temp();
            $this->prt_temp();
        } else {
            $this->get_img();
        }
    }

    function get_img() {
        $h = new home();
        $this->prt_iterm_In($h->get_temp_img($this->id));
    }

    function get_temp() {
        $h = new home();
        if ($this->cur_seg != '') {
            $url = new Url(MAIN_SEG);
            $cur = $url->segment($this->cur_seg);
            $this->cur = is_int($cur) ? $cur : 0;
        } else {
            $this->cur = 0;
        }
        $this->a_temp = $h->get_template($this->cat_id, $this->cur, $this->ran);
    }

    function prt_temp() {
        echo '<div class="Box_Temp">';
        foreach ($this->a_temp as $value) {
            $this->cat_id !== 0 ? $this->prt_iterm($value) : $this->prt_iterm_spec($value);
        }

        echo '<div class="clear"></div></div>';
    }

    public function prt_iterm_spec($value) {
        ?>
        <div class="Temp_C" style="width: <?php echo $this->size_out['w'] * 2 ?>px;margin:20px <?php echo $this->size_out['m'] ?>px;">
            <div class="img" style="float:left;width: <?php echo $this->size_out['w'] ?>px;height: <?php echo $this->size_out['h'] ?>px">
                <a href="<?php echo URL . 'mau-website/' . vn_to_en($value['cat_name']) . '.' . $value['id_cat'] . '/' . $value['id'] ?>"><img class="Temp_Img" title="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" alt="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" width="<?php echo $this->size_out['w'] ?>" src="<?php echo URL . 'public/' . $value['file_temp_255xX']; ?>" /></a>
            </div>
            <div class="t_info" style="height: <?php echo $this->size_out['w'] - 10 ?>px">
                <h4><?php echo $this->lan['news_spe'] . ' S-' . $value['id'] ?></h4>
                <a href="<?php echo URL . 'demo/' . $value['id'] ?>"><div class="But"><?php echo $this->lan['info_v'] ?></div></a>
                <div class="clear"></div>
                <?php echo base64_decode($value['temp_dis']); ?>
            </div>
        </div>
        <?php
    }

    function prt_iterm($value) {
        ?>
        <div class="Temp_C" style="width: <?php echo $this->size_out['w'] ?>px;margin:20px <?php echo $this->size_out['m'] ?>px;">
            <div class="img" style="height: <?php echo $this->size_out['w'] ?>px">
                <?php if ($this->detail) { ?>
                    <div class="Zoom"  style="height:<?php echo $this->size_out['h'] - 58 ?>px;line-height:<?php echo $this->size_out['h'] + 20 ?>px;width:<?php echo $this->size_out['w'] ?>px">
                        <img class="zoom_img" alt="<?php echo URL . 'public/' . $value['file_temp']; ?>" src="<?php echo URL . 'template/' . MOD . '/images/zoom.png' ?>" />
                        <a href="<?php echo URL . 'mau-website/' . vn_to_en($value['cat_name']) . '.' . $value['id_cat'] . '/' . $value['id'] ?>"><img alt="chi tiết" src="<?php echo URL . 'template/' . MOD . '/images/info.png' ?>" /></a>
                    </div>
                    <a href="<?php echo URL . 'mau-website/' . vn_to_en($value['cat_name']) . '.' . $value['id_cat'] . '/' . $value['id'] ?>"><img class="Temp_Img" title="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" alt="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" width="<?php echo $this->size_out['w'] ?>" src="<?php echo URL . 'public/' . $value['file_temp_255xX']; ?>" /></a>
                <?php } else { ?>
                    <a href="<?php echo URL . 'mau-website/' . vn_to_en($value['cat_name']) . '.' . $value['id_cat'] . '/' . $value['id'] ?>"><img class="Temp_Img" title="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" alt="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" width="<?php echo $this->size_out['w'] ?>" src="<?php echo URL . 'public/' . $value['file_temp_255xX']; ?>" /></a>
                <?php } ?>
            </div>
        </div>
        <?php
    }

    function prt_iterm_In($value) {
        ?>
        <div class="Temp_C" style="width: <?php echo $this->size_in['w'] ?>px">
            <div class="img" style="height: <?php echo $this->size_in['h'] ?>px">
                <div class="Zoom" style="height:<?php echo $this->size_in['h'] ?>px;line-height:<?php echo $this->size_in['h'] + 20 ?>px;width:<?php echo $this->size_in['w'] ?>px">
                    <img class="zoom_img" alt="<?php echo URL . 'public/' . $value['file_temp']; ?>" src="<?php echo URL . 'template/' . MOD . '/images/zoom.png' ?>" />
                </div>
                <img class="Temp_Img" title="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" alt="<?php echo $this->lan['name_f'] . ' T_' . $value['id'] ?>" width="<?php echo $this->size_in['w'] ?>px" src="<?php echo URL . 'public/' . $value['file_temp']; ?>" /></a>
            </div>
        </div>
        <?php
    }

    function pagging() {
        
    }

}
